package com.sfpay.test.springmvc;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
	@Resource          //���Ϊ���ע��ķ�ʽ���൱����ǰ�������ļ����洴����
	                   //һ��bean,���ھͿ��Բ���new����,�Ϳ���ֱ������ʹ���ˣ��������Ҫ�������ļ�����
	                  //дһ��<context:component-scan base-package="com.sfpay.*" />
	                  //��Ϊ@Resource��@Component��һ��ġ�����
	LoginService loginService;
	
	
	
	
	

	/*
	 * @RequestMapping("/login") public String login(@RequestParam("username")
	 * String username,*
	 * 
	 * @RequestParam("password") String password) { System.out.println(username
	 * + " " + password); return "login_success"; }
	 * 
	 * @RequestMapping("/login") public ModelAndView
	 * login(@RequestParam("username") String username,@RequestParam("password")
	 * String password){
	 * System.out.println("username"+"-----"+username+"___"+"password"
	 * +"-----"+password); ModelAndView maView=new ModelAndView();
	 * maView.addObject("username", username); //
	 * request.setAttribute("username", username); maView.addObject("password",
	 * password); maView.setViewName("login_success"); return maView; }
	 */

	@RequestMapping("/login")
	public String login(Model model) {
/*		System.out.println("username" + "-----" + username + "___" + "password"
				+ "-----" + password);
//		model.addAttribute("username", username);//���Ҳ�ǿ��Է��ض������͵ġ���
*/		student student=loginService.setStudent("deng", "351533");
		model.addAttribute("name", student.getName());
		model.addAttribute("id", student.getId());
		model.addAttribute(student);
		return "login_success";
	}

	@RequestMapping("/json1")
	@ResponseBody
	public String json1() {
		return "success";
	}

	@RequestMapping("/json2")
	@ResponseBody
	public Object[] json2(@RequestParam("username")String username, @RequestParam("no")String no) {
		return new String[] { username, no + "---" };
	}
	
	@RequestMapping("/login3")
	public String login3(Model model){
		model.addAttribute("helloworld", "welcome");
		return "login_success";
	}
}
